import React,{Component} from 'react';
import 'styles/supplier-management/air-ticket-quotation/air-ticket-quotation.scss';
import airTicketColumns from './air-ticket-columns';
import airTicketUtil from './air-quotation-util';
import {messages} from "share/common";
import AdvanceTable from 'components/advanced-table';
import airServer from './air-ticket-server';
import menuRoute from 'routes/menuRoute';

class AirTicketQuotation extends Component{

  constructor(props){
    super(props);
    this.columns = airTicketColumns.getColumns();
    this.state = {
      searchFormData: airTicketUtil.getFormItems(),
      pagination: {
        // current: 1,
        pageSize: 10,
        showSizeChanger: false, // 隐藏pageSize选择
        showQuickJumper: false, // 隐藏页码跳转
        // total: 0
      }
    }
    this.searchParams = {};
  }

  createTableOption = () => {
    const {searchFormData, pagination} = this.state;
    return {
      title: messages('supplier.key982')/*机票方案报价*/,
      key: 'airTicketQuotation',
      tableName: 'airTicketQuotation',
      service: this.advanceTableServer,
      index: true,
      pagination: pagination,
      onRef: this.advanceTableRef,
      rowKey: record => record.companyCode,
      columns: this.columns,
      searchForm: searchFormData,
      bordered: true,
      onRow: (record) => {
        return {
          onClick: () => {
            this.onJumpDetail(record);
          }
        };
      }
    }
  }

  /**
   * 跳转详情
   * @param record 表格被点击行数据
   */
  onJumpDetail = (record) => {
    this.context.router.push(menuRoute.getRouteItem('ticket-quotation-detail', 'key').url.replace(':id', record.id));
  }

  advanceTableRef = (ref) => {
    this.tableRef = ref;
  }

  advanceTableServer = (page, size, searchValues) => {
    this.searchParams = Object.assign({},this.searchParams, searchValues, {pageNo: page+1, pageSize: 10});
    return airServer(this).getAirTicketListData(this.searchParams);
  }

  render(){

    return (
      <div className='air-ticket-quotation'>
        <div style={{height: 'calc(100vh - 66px)'}}>
          <AdvanceTable {...this.createTableOption()} />
        </div>
      </div>
    )
  }
}

AirTicketQuotation.contextTypes = {
  router: React.PropTypes.object
};

export default AirTicketQuotation;
